<?php

//use yii\web\View;

use yii\helpers\Url;
use common\models\Word;

?>
<?php echo $this->render("/layouts/top")?>

<style>

.questiondiv{


	margin:0px auto; 
	margin-top:1px; 
	width:1000px; 

	line-height:28px; 
	background-color:#EEE;

}

.questiondiv span{

	
}

ul{margin:0;padding:0;list-style:none;}  


.rightnum{
	display:inline-block;
	padding:0px;
	width:50px; 
	height:28px; 
	font-size:18px;
	text-align:center;
}


</style>
<script type="text/javascript" src="/js/NoLimitCategory.js"></script>
<?php echo $this->render("/module/baseinfo")?>
<?php

//print_r($words);
	for($i=0; $i<count($words); $i++){

		$cname1 = empty($words[$i]["cname"]) ? "" : "[".$words[$i]["cname"]."]";
		$cname2 = empty($words[$i]["cname2"]) ? "" : "[".$words[$i]["cname2"]."]";
		$cname3 = empty($words[$i]["cname3"]) ? "" : "[".$words[$i]["cname3"]."]";
		$cname4 = empty($words[$i]["cname4"]) ? "" : "[".$words[$i]["cname4"]."]";
		$cname5 = empty($words[$i]["cname5"]) ? "" : "[".$words[$i]["cname5"]."]";
		
		$category = $cname1.$cname2.$cname3.$cname4.$cname5;
		//echo $category;
		
		$word = empty($words[$i]["word"]) ? "" : $words[$i]["word"];
		$ipa_en = empty($words[$i]["ipa_en"]) ? "" : stripcslashes($words[$i]["ipa_en"]);
		$ipa_us = empty($words[$i]["ipa_us"]) ? "" : stripcslashes($words[$i]["ipa_us"]);
		$trans = empty($words[$i]["trans"]) ? "" : $words[$i]["trans"];
		
		$correct_write = $words[$i]["correct_write"];
		
		$isfav = ($words[$i]["f_id"]>0) ? '★' : '☆';
		
		$color = \common\components\Common::getRightColor($correct_write);
		
		$curtime = time();
		
		$last_right_time = $words[$i]["correct_time"];

		$locktime = \common\components\Common::getLocktime($correct_write);
		
		if($last_right_time+$locktime > $curtime){
			$questioncolor = '#BBB';
		}else{
			$questioncolor = '#000';
		}
		
		$trans_arr = explode('|', $trans);
		$question = empty($words[$i]["question"]) ? Word::getTransStr($trans_arr) : $words[$i]["question"];
		

			$answer = '<h1>'.$words[$i]["word"].'</h1>';
			
			if(!empty($words[$i]["ipa_en"])){
				$answer .= '英<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($words[$i]["ipa_en"]).'</span>';
			}
			
			if(!empty($words[$i]["ipa_en"])){
				$answer .= '　美<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($words[$i]["ipa_us"]).'</span>';
			}
			
			$trans = explode('|', $words[$i]["trans"]);

			$trans_str = '';
			if(count($trans) > 0){
				$trans_str = implode('<br>', $trans);
				$answer .= '<br><br>'.$trans_str;
			}


?>

<div class="questiondiv"><!--
 --><span style="display:inline-block; width:50px; text-align:center"><?php echo $words[$i]["id"]?></span>  <!--
 --><span style="display:inline-block; width:776px; color:<?php echo $questioncolor?>;">
  <?php echo $category?> <?php echo $question?>
  </span><!--
 --><span class="rightnum"><strong style="color:<?php echo $color?>;"><?php echo $correct_write?></strong></span>  <!--
 --><span style="display:inline-block; width:50px; text-align:center;"><?php echo $isfav?></span>  <!--
 --><span style="display:inline-block; width:50px; text-align:center;"><input type="button" value="答案" onclick="seeanswer(this)" /></span>  
</div>

<div style="margin:0px auto; width:1000px;display:none">
  <div style="padding:4px;">
  <?php echo $answer?>
  </div>
  <div style="margin:0px auto; width:100%; text-align:center; padding:4px; padding-bottom:8px;">
    <input type="button" value="收起答案" onclick="closeanswer(this)"/> 
    <input type="button" value="编辑单词" onclick="edit(<?php echo $words[$i]["id"]?>)"/>
	<input type="button" value="收藏单词" onclick="favorite(<?php echo $words[$i]["id"]?>)"/>
    <input type="button" value="直接毕业" onclick="graduate(<?php echo $words[$i]["id"]?>)"/>
    <input type="button" value="回答正确" onclick="correct_write(<?php echo $words[$i]["id"]?>)"/>
  </div>
</div>
<?php
	}
?>

<br>

<?php
	$pageurl = "?c1=$c1&c2=$c2&c3=$c3&cid=$cid&searchtext=$searchtext&transtext=$transtext&correct=$correct&tags=$tags&page=";
	
?>
<div style=" margin:0px auto; width:1000px; height:28px; line-height:28px; background-color:#EEE; text-align:center">
<span>总数据:<?php echo $pv->dataCount?>条</span>
<a href="<?php echo $pageurl."1"?>">首页</a>
<a href="<?php echo $pageurl.$pv->prevPage?>">上一页</a>
<span><?php echo $pv->currentPage."/".$pv->pageCount?></span>
<a href="<?php echo $pageurl.$pv->nextPage?>">下一页</a>
<a href="<?php echo $pageurl.$pv->pageCount?>">末页</a>
</div>

<script language="javascript">


function search(){
	var searchtext = $('#searchtext').val();
	var transtext = $('#transtext').val();
	var categorys = nlc.getSelects();
	var correct = getCorrectParam();
	var tags = getTagsParam();

	var c1=0, c2=0, c3=0, cid = 0;
	for(var i=0; i<categorys.length; i++){
		if(i == 0)c1 = categorys[i].value;
		if(i == 1)c2 = categorys[i].value;
		if(i == 2)c3 = categorys[i].value;
		if(categorys[i].value > 0)cid = categorys[i].value;//所属分类为不为0的最后一个
	}

	var pageurl = "?"+"c1="+c1+"&c2="+c2+"&c3="+c3+"&cid="+cid+"&searchtext="+encodeURIComponent(searchtext)+"&transtext="+encodeURIComponent(transtext)
	+"&correct="+correct+"&tags="+tags+"&page="+page;

	window.location.href = pageurl;

}

function seeanswer(obj){

	var div = $(obj).parent().parent().next();

	var h = div.height();

	div.css('display', 'block');
	div.css('height', '0px');
	
	div.animate({height:h}, 500);

}

function closeanswer(obj){
	var div = $(obj).parent().parent();
	var h = div.height();
	
	div.animate({height:'0px'}, 500, function(){
		div.css('display', 'none');
		div.height(h);//重新给它高度，否则下次展开的时候不灵，因为展开的时候这个高度需要读出来
	});
}

function edit(wid){
	window.location.href = "<?php echo Url::to(['/word/edit'])?>"+"?id="+wid;
}

function favorite(kid){
	new Ajax().get({
		url : "<?php echo Url::to(['/word/favorite'])?>"+"?id="+kid,
		resultType : 'json',
		onLoaded : function(result){
			console.log(result);
			if(result.code == 1){
				alert("成功");
				window.location.reload();
			}else{
				alert(result.info);
			}
		}
						
	});
}


//说、写 回答正确
function correct_write(id){
	new Ajax().get({
		url : "<?php echo Url::to(['/word/async-correct-write'])?>"+"?id="+id,
		resultType : 'json',
		onLoaded : function(result){
			if(result.code == 1){
				alert("成功");
				window.location.reload();
			}else{
				alert(result.info);
			}
		}
	});
}


//直接毕业
function graduate(id){
	new Ajax().get({
		url : "<?php echo Url::to(['/word/async-graduate'])?>"+"?id="+id,
		resultType : 'json',
		onLoaded : function(result){
			if(result.code == 1){
				alert("成功");
				window.location.reload();
			}else{
				alert(result.info);
			}
		}
	});
}



</script>
<br>
<?php echo $this->render("/layouts/footer")?>
